import pytesseract
from PIL import Image
import re
import cv2
import numpy as np


#tesseract 路径
pytesseract.pytesseract.tesseract_cmd = r'E:\Program Files\tesseract.exe'

# C:\Users\liulu\Desktop\testImag.jpg
#读图
imagePath = input('your image path')
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 二值化处理
_, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)

# 保存处理后的图片
cv2.imwrite('processed_image.png', thresh)

# 读取处理后的图片
image = Image.open('processed_image.png')

text = pytesseract.image_to_string(image)

print("原始文字",text)

cleaned_text = re.sub(r'[^\d\s.]', '', text)

numbers = cleaned_text.split()

print("最终文字",numbers)
